/*
-----------------------------------------------------------------------------
This source file is part of Labor3D
(Labor 3D Graphics Engine)

Copyright (c) 2009-2020 Rock Mao
* creator : Rock Mao
* created : 2009-5-4   14:52
* filename: LaborSingleton.h
-----------------------------------------------------------------------------
*/

#ifndef __LABORSINGLETON_H__
#define __LABORSINGLETON_H__
#include "../LaborCoreDef.h"

NAMESPACE_LABOR3D_BEGIN

/** Template class for creating single-instance global classes.
*/
#pragma  warning(disable : 4661)

template <typename T> class CLSingleton
{
protected:

	static T* ms_Singleton;

public:
	CLSingleton( void )
	{
		assert( !ms_Singleton );
		ms_Singleton = static_cast<T*>(this);
	}
	~CLSingleton( void )
	{  
		assert( ms_Singleton ); 
		ms_Singleton = 0;  
	}
	static T& getSingleton( void )
	{	
		assert( ms_Singleton ); 
		return ( *ms_Singleton );
	}
	static T* getSingletonPtr( void )
	{
		if (!ms_Singleton)
		{
			ms_Singleton = new T();			
		}
		return ms_Singleton;
	}
};

NAMESPACE_LABOR3D_END

#endif